/*
 * InputProviderModel.java
 *
 * Stateroom - Java framework library for finite state machines
 * Copyright (C) 2009 by Matthew Werny
 * All Rights Reserved
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.iceflow.stateroom.models;

import net.iceflow.stateroom.Utility;
import net.iceflow.stateroom.interfaces.InputProvider;
import net.iceflow.stateroom.interfaces.Model;

/**
 * Machine model that uses an input provider to determine whether the machine has a necessary condition to stop operation.
 * @param <T> Type used to represent the input alphabet for the input provider
 */
public class InputProviderModel<T> implements Model {
	
	/**
	 * Input provider from which to get input objects.
	 */
	private final InputProvider<T> _provider;
	
	/**
	 * Constructs a new InputProviderModel using the provided InputProvider.
	 * @param provider Provider instance to use in the model
	 */
	public InputProviderModel(final InputProvider<T> provider) {
		Utility.validateNotNull(provider, "provider may not be null.");
		
		this._provider = provider;
	}
	
	/**
	 * Indicates whether there is a sufficient condition for stopping the operation of the machine.
	 * @return truth of whether an end condition exists
	 */
	@Override
	public final boolean isEnd() {
		boolean truthOfEnd = false;
		
		if (!this._provider.isInputAvailable()) {
			truthOfEnd = true;
		}
		
		return truthOfEnd;
	}
	
	/**
	 * Getter for the provider.
	 * @return the provider of the series of input values
	 */
	public final InputProvider<T> getProvider() {
		return this._provider;
	}
}
